﻿using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using DanTriNews.Resources;

namespace DanTriNews.ViewModels
{
    public class DanTriViewModel : INotifyPropertyChanged
    {
        public DanTriViewModel()
        {
            this.Categories = new ObservableCollection<CategoryViewModel>();
            IsDataLoaded = false;
        }

        public ObservableCollection<CategoryViewModel> Categories { get; private set; }

        public bool IsDataLoaded
        {
            get;
            set;
        }

        /// <summary>
        /// Creates and adds a few ItemViewModel objects into the Items collection.
        /// </summary>
        public void LoadData(int categoryId)
        {
            if (!IsDataLoaded)
            {
                Categories.Add(new CategoryViewModel(0, "Video", "http://m.dantri.com.vn/video-page.htm"));
                Categories.Add(new CategoryViewModel(728, "Sự kiện", "http://m.dantri.com.vn/su-kien.htm"));
                Categories.Add(new CategoryViewModel(20, "Xã hội", "http://m.dantri.com.vn/xa-hoi.htm"));
                Categories.Add(new CategoryViewModel(36, "Thế giới", "http://m.dantri.com.vn/the-gioi.htm"));
                Categories.Add(new CategoryViewModel(26, "Thể thao", "http://m.dantri.com.vn/the-thao.htm"));
                Categories.Add(new CategoryViewModel(25, "Giáo dục", "http://m.dantri.com.vn/giao-duc.htm"));
                Categories.Add(new CategoryViewModel(167, "Nhân ái", "http://m.dantri.com.vn/nhan-ai.htm"));
                Categories.Add(new CategoryViewModel(76, "Kinh doanh", "http://m.dantri.com.vn/kinh-doanh.htm"));
                Categories.Add(new CategoryViewModel(730, "Văn hóa", "http://m.dantri.com.vn/van-hoa.htm"));
                Categories.Add(new CategoryViewModel(23, "Giải trí", "http://m.dantri.com.vn/giai-tri.htm"));
                Categories.Add(new CategoryViewModel(170, "Pháp luật", "http://m.dantri.com.vn/phap-luat.htm"));
                Categories.Add(new CategoryViewModel(135, "Nhịp sống trẻ", "http://m.dantri.com.vn/nhip-song-tre.htm"));
                Categories.Add(new CategoryViewModel(130, "Tình yêu", "http://m.dantri.com.vn/tinh-yeu-gioi-tinh.htm"));
                Categories.Add(new CategoryViewModel(7, "Sức khỏe", "http://m.dantri.com.vn/suc-khoe.htm"));
                Categories.Add(new CategoryViewModel(119, "Sức mạnh tri thức", "http://m.dantri.com.vn/suc-manh-tri-thuc.htm"));
                Categories.Add(new CategoryViewModel(111, "Xe++", "http://m.dantri.com.vn/o-to-xe-may.htm"));
                Categories.Add(new CategoryViewModel(835, "Du lịch", "http://m.dantri.com.vn/du-lich.htm"));
                Categories.Add(new CategoryViewModel(132, "Chuyện lạ", "http://m.dantri.com.vn/chuyen-la.htm"));
                Categories.Add(new CategoryViewModel(133, "Việc làm", "http://m.dantri.com.vn/viec-lam.htm"));
                Categories.Add(new CategoryViewModel(702, "Blog", "http://m.dantri.com.vn/blog.htm"));
                Categories.Add(new CategoryViewModel(734, "Du học", "http://m.dantri.com.vn/du-hoc.htm"));
                Categories.Add(new CategoryViewModel(704, "Tuyển sinh", "http://m.dantri.com.vn/tuyen-sinh.htm"));
                Categories.Add(new CategoryViewModel(673, "Diễn đàn", "http://m.dantri.com.vn/dien-dan.htm"));
                Categories.Add(new CategoryViewModel(202, "Bạn đọc", "http://m.dantri.com.vn/ban-doc.htm"));
                this.IsDataLoaded = true;
            }
            foreach(CategoryViewModel c in Categories)
            {
                if(c.Id==categoryId)
                {
                    c.Loaddata();
                    break;
                }
            }
        }
        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(String propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (null != handler)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        public CategoryViewModel FindCategory(int Id)
        {
            foreach(CategoryViewModel v in Categories)
            {
                if (v.Id == Id)
                    return v;
            }
            return null;
        }
    }
}